/**
 *
 * Created by Song,YeWen, 10/10/2011 11:27:17 AM
 *
 */

function  validateVideoUrl(ori_url) 
{
    //We use a fake constant duration for m1905.com, because it is Trailer, not long duration video
    //TODO: FIXME
    var fcduration = '100'; 
	var html = download_page(ori_url);
	var matches = html.match(/videoid="(\d+)"/);
	if (!matches) {
		// Not Found
	  	return 'NotFoundVideo';
	}
	var dst_url = 'http://www.m1905.com/api/video/api_play-p-id-' + matches[1] + '.html';
	var xml_str = download_page(dst_url);
	var flv_str = parse_xml_attribute(xml_str, 'playlist', 'item', 'url');
	
	//matches = html.match(/<title>(.*?)<\/title>/);
	matches = html.match(/<title>([\s\S]*?)<\/title>/);
    if(matches){
 	   return 'success_title:' + encodeURIComponent(matches[1])
 	          + '\n video_urls:' + encodeURIComponent(flv_str)
 	          + '\n seconds:' + Math.round(parseInt(fcduration));
    }
    return 'error:empty_path';
}

/* http://www.m1905.com/api/video/api_play-p-id-472083.html */
/* http://www.m1905.com/video/play/472083.shtml */
function js_get_media_url(ori_url) 
{
	var html = download_page(ori_url);
	var matches = html.match(/videoid="(\d+)"/);
	if (!matches) {
		// Not Found
		return '';
	}
    
	var dst_url = 'http://www.m1905.com/api/video/api_play-p-id-' + matches[1] + '.html';
	var xml_str = download_page(dst_url);
	var flv_str = parse_xml_attribute(xml_str, 'playlist', 'item', 'url');
	
	return flv_str;
}
